package yxy.game.pm2.command.plainsarena;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.PlainsArenaMessage;
import yxy.game.pm2.module.plainsarena.PlainsArenaHandle;

/** 中原擂台 中原擂台段位奖励 */
@MessageType(proto = Command.PlainsArenaLevelReward, classtype = PlainsArenaMessage.PlainsArenaLevelRewardRequest.class)
public class CMD_PlainsArenaLevelReward extends Command<PlainsArenaMessage.PlainsArenaLevelRewardRequest> {

	@Override
	public void execute(MessageSource messageSource, PlainsArenaMessage.PlainsArenaLevelRewardRequest request) {
		String playerCode = messageSource.getTag();
		int level = request.getLevel();

		PlainsArenaMessage.PlainsArenaLevelRewardResponse.Builder response = PlainsArenaMessage.PlainsArenaLevelRewardResponse.newBuilder();

		Result result = new PlainsArenaHandle().levelReward(playerCode, level, response);

		send(messageSource, response, result);
	}

	private void send(MessageSource messageSource, PlainsArenaMessage.PlainsArenaLevelRewardResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}